import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-12-24
 * Time:18:04
 */
public class DBUtil {
    private static volatile DataSource dataSource=null;

    public static DataSource getDataSource() {
        if(dataSource==null){
            synchronized (DBUtil.class){
                if(dataSource==null){
                    dataSource =new MysqlDataSource();
                    ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java105?characterEncoding=utf8&useSSL=false");
                    ((MysqlDataSource)dataSource).setUser("root");
                    ((MysqlDataSource)dataSource).setPassword("lkh201216");

                }
            }
        }
        return dataSource;
    }
    private DBUtil(){};
}
